package cc.minos.servers.filters
{
	
	public class EmoticonFilter
	{
		
		public static var images:Object = {};
		
		/**
		 * to short [/alert]
		 * @param	s
		 * @return
		 */
		public static function encode( s:String ):String
		{
			//s = s.toLowerCase();
			var face:String = s;
			for ( var i:String in images )
			{
				if ( images[ i ] == face )
				{
					s = i;
					break;
				}
			}
			return s;
		}
		
		private static var unReg:RegExp = /\[\/.*?\]/g;
		
		/**
		 * to html <img/>
		 * @param	s
		 * @return
		 */
		public static function decode( s:String ):String
		{
			return s.replace( unReg , replaceShort );
		}
		
		private static function replaceShort( r:String , p:int , s:String ):String
		{
			r = r.toLowerCase();
			return buildURL( images[r] );
		}
		
		private static function buildURL( imagePath:String ):String
		{
			return "<img border=\"0\" src=\"" + imagePath + "\">";
		}
	
	}
}
